class Solution {
public:
    vector<int> maxInWindows(vector<int>& num, int sz) {
        if (sz == 0 || sz > num.size()) return vector<int>();
        int l = 0, r = 0, maxn = -1;
        queue<int> q;
        vector<int> res;
        while (r < sz) {
            maxn = max(maxn, num[r]);
            q.push(num[r++]);
        }
        res.push_back(maxn);
        while (r < num.size()) {
            int tmp = q.front();
            q.pop();
            q.push(num[r]);
            l++;
            if (tmp == maxn) {
                maxn = *max_element(num.begin() + l, num.begin() + r + 1);
            } else {
                maxn = max(maxn, num[r]);
            }
            res.push_back(maxn);
            r++;
        }
        return res;
    }
};